package com.iknow.view.widget.zoom;

import android.content.Context;
import android.os.Vibrator;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;

public class LongPressZoomListener
  implements View.OnTouchListener
{
  private static final long VIBRATE_TIME = 50L;
  private float mDownX;
  private float mDownY;
  private final Runnable mLongPressRunnable;
  private final int mLongPressTimeout;
  private Mode mMode = Mode.UNDEFINED;
  private final int mScaledMaximumFlingVelocity;
  private final int mScaledTouchSlop;
  private VelocityTracker mVelocityTracker;
  private final Vibrator mVibrator;
  private float mX;
  private float mY;
  private DynamicZoomControl mZoomControl;

  public LongPressZoomListener(Context paramContext)
  {
    this.mLongPressRunnable = new Runnable(this)
    {
      public void run()
      {
        LongPressZoomListener.access$0(this.this$0, LongPressZoomListener.Mode.ZOOM);
        LongPressZoomListener.access$1(this.this$0).vibrate(50L);
      }
    };
    this.mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
    this.mScaledTouchSlop = ViewConfiguration.get(paramContext).getScaledTouchSlop();
    this.mScaledMaximumFlingVelocity = ViewConfiguration.get(paramContext).getScaledMaximumFlingVelocity();
    this.mVibrator = ((Vibrator)paramContext.getSystemService("vibrator"));
  }

  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    int i = paramMotionEvent.getAction();
    float f1 = paramMotionEvent.getX();
    float f2 = paramMotionEvent.getY();
    if (this.mVelocityTracker == null)
      this.mVelocityTracker = VelocityTracker.obtain();
    this.mVelocityTracker.addMovement(paramMotionEvent);
    switch (i)
    {
    default:
      this.mVelocityTracker.recycle();
      this.mVelocityTracker = null;
      paramView.removeCallbacks(this.mLongPressRunnable);
      this.mMode = Mode.UNDEFINED;
    case 0:
      while (true)
      {
        return true;
        this.mZoomControl.stopFling();
        paramView.postDelayed(this.mLongPressRunnable, this.mLongPressTimeout);
        this.mDownX = f1;
        this.mDownY = f2;
        this.mX = f1;
        this.mY = f2;
      }
    case 2:
      float f3 = (f1 - this.mX) / paramView.getWidth();
      float f4 = (f2 - this.mY) / paramView.getHeight();
      if (this.mMode == Mode.ZOOM)
        this.mZoomControl.zoom((float)Math.pow(20.0D, -f4), this.mDownX / paramView.getWidth(), this.mDownY / paramView.getHeight());
      while (true)
      {
        float f5;
        float f6;
        do
        {
          while (true)
          {
            while (true)
            {
              this.mX = f1;
              this.mY = f2;
            }
            if (this.mMode != Mode.PAN)
              break;
            this.mZoomControl.pan(-f3, -f4);
          }
          f5 = this.mDownX - f1;
          f6 = this.mDownY - f2;
        }
        while ((float)Math.sqrt(f5 * f5 + f6 * f6) < this.mScaledTouchSlop);
        paramView.removeCallbacks(this.mLongPressRunnable);
        this.mMode = Mode.PAN;
      }
    case 1:
    }
    if (this.mMode == Mode.PAN)
    {
      this.mVelocityTracker.computeCurrentVelocity(1000, this.mScaledMaximumFlingVelocity);
      this.mZoomControl.startFling(-this.mVelocityTracker.getXVelocity() / paramView.getWidth(), -this.mVelocityTracker.getYVelocity() / paramView.getHeight());
    }
    while (true)
    {
      while (true)
      {
        this.mVelocityTracker.recycle();
        this.mVelocityTracker = null;
        paramView.removeCallbacks(this.mLongPressRunnable);
        this.mMode = Mode.UNDEFINED;
      }
      this.mZoomControl.startFling(0F, 0F);
    }
  }

  public void setZoomControl(DynamicZoomControl paramDynamicZoomControl)
  {
    this.mZoomControl = paramDynamicZoomControl;
  }

  private static enum Mode
  {
    static
    {
      PAN = new Mode("PAN", 1);
      ZOOM = new Mode("ZOOM", 2);
      Mode[] arrayOfMode = new Mode[3];
      arrayOfMode[0] = UNDEFINED;
      arrayOfMode[1] = PAN;
      arrayOfMode[2] = ZOOM;
      ENUM$VALUES = arrayOfMode;
    }
  }
}